package com.xxc.comtroller;

import com.xxc.entity.City;
import com.xxc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiangcheng
 * @version 2022/6/21 15:48
 * @since JDK8
 */
@RestController
@RequestMapping("/cities")
public class CityController {

    private CityService cityService;

    @Autowired
    public void setCityService(CityService cityService) {
        this.cityService = cityService;
    }



    @GetMapping
    public List<City> cities(){
        return cityService.queryAll();
    }

    @PostMapping
    public City create(@RequestBody City city){
        return cityService.insert(city);
    }

    @GetMapping("{id}")
    public City city(@PathVariable("id") Integer id){
        return cityService.queryById(id);
    }

}
